#install.packages(c("RApiSerialize", "LAGOSNE", 'USAboundaries'))
#LAGOSNE::lagosne_get(dest_folder = LAGOSNE:::lagos_path())
# #Lagos download script
#LAGOSNE::lagosne_get(dest_folder = LAGOSNE:::lagos_path())
#Load in lagos
lagos <- lagosne_load()
## Warning in (function (version = NULL, fpath = NA) : LAGOSNE version unspecified,
## loading version: 1.087.3
#Grab the lake centroid info
lake_centers <- lagos$locus
#Look at the column names
#names(lake_centers)
#Look at the structure
#str(lake_centers)
#View the full dataset
#View(lake_centers %>% slice(1:100))
spatial_lakes <- st_as_sf(lake_centers,coords=c('nhd_long','nhd_lat'),
crs=4326) %>%
st_transform(2163)
#Subset for plotting
subset_spatial <- spatial_lakes %>%
slice(1:100)
subset_baser <- spatial_lakes[1:100,]
#Dynamic mapviewer
mapview(subset_spatial)
states <- us_states()
#Plot all the states to check if they loaded
#mapview(states)
minnesota <- states %>%
filter(name == 'Minnesota') %>%
st_transform(2163)
#Subset lakes based on spatial position
minnesota_lakes <- spatial_lakes[minnesota,]
#Plotting the first 1000 lakes
minnesota_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
st_transform(4326) %>%
mapview()
mapviewOptions(fgb = F)
IAandIL <- states %>%
filter(name %in% c('Iowa', 'Illinois')) %>%
st_transform(2163)
mapview(IAandIL)
#Subset lakes based on spatial position
IAandIL_lakes <- spatial_lakes[IAandIL,]
nrow(IAandIL_lakes)
## [1] 16466
nrow(minnesota_lakes)
## [1] 29038
Illinois and Iowa have 16,466 sites. Minnesota has 29,038 sites. This is nearly double the number of sites, compared to Illinois and Iowa combined.
iowa <- states %>%
filter(name == 'Iowa') %>%
st_transform(2163)
iowa_lakes <- spatial_lakes[iowa,]
iowa_lakes$state <- 'Iowa'
minnesota_lakes$state <- 'Minnesota'
IAandMN_lakes <- bind_rows(iowa_lakes, minnesota_lakes)
names(IAandMN_lakes)
## [1] "lagoslakeid" "nhdid" "gnis_name"
## [4] "lake_area_ha" "lake_perim_meters" "nhd_fcode"
## [7] "nhd_ftype" "iws_zoneid" "hu4_zoneid"
## [10] "hu6_zoneid" "hu8_zoneid" "hu12_zoneid"
## [13] "edu_zoneid" "county_zoneid" "state_zoneid"
## [16] "elevation_m" "state" "geometry"
ggplot(IAandMN_lakes) + aes(x=lake_area_ha, fill = state) +geom_histogram()+ scale_x_log10() + ylab('Frequency') +xlab('Lake Size in Hectares') + facet_wrap(vars(state))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
There are more lakes in Minnesota than in Iowa, but the distribution of lakes is similar. For both states there are a greater number of smaller lakes, and a smaller number of large lakes.
mapview(IAandIL_lakes, zcol = "lake_area_ha", at = c(0, 5, 10, 100, 250, 500, 750, 1000, 5000, 10000))